/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package assisisw.smartcal.notificationsubsystem;

import assisisw.smartcal.entitysubsystem.Event;
import assisisw.smartcal.entitysubsystem.INotificationController;
import assisisw.smartcal.entitysubsystem.Notification;
import assisisw.smartcal.entitysubsystem.User;
import assisisw.smartcal.webuisubsystem.managedbean.DashboardBean;
import assisisw.smartcal.webuisubsystem.managedbean.INotificationClientsEndpoint;
import javax.ejb.EJB;
import javax.ejb.Singleton;

/**
 *
 * @author Francesco
 */
@Singleton
public class NotificationManager implements INotificationManager
{

    // Instance Fields
    
    /***/
    @EJB ()
    private INotificationClientsEndpoint notificationClientsEndpoint ;
    
    /***/
    @EJB ()
    private INotificationController notificationController ;
    
    // Instance Methods
    
    /***/
    public NotificationManager () {}
    
    /**
     * AS THE SUPER'S ONE.
     */
    @Override
    public void generateNotification ( Notification.NotificationType type , Event generatingEvent , User recipient , String message ) 
    {
        Notification newNot ;
        DashboardBean dashboardBean ;
        newNot = notificationController.insert ( type , generatingEvent , recipient , message ) ;
        dashboardBean = notificationClientsEndpoint.getDashboardBean ( recipient ) ;
        if ( dashboardBean != null )
            dashboardBean.onNotificationAdded ( newNot ) ;
    }
    
}
